﻿// Copyright (C) 2009  Lex Li
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

/*
 * Created by SharpDevelop.
 * Date: 9/18/2009
 * Time: 7:16 PM
 */
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

using Lextm.M8Pack.ThemeBuilder.Properties;

namespace Lextm.M8Pack.ThemeBuilder
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	internal partial class MainForm : Form
	{		
		private readonly static string DefaultTheme = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "default.mth");
		private readonly Model _model;
		
		public MainForm()
		{
		    InitializeComponent();
			ClientSize = new Size(480, 770);
			_model = new Model(dockPanel1);
			Text = Text + " (Version: " + Assembly.GetExecutingAssembly().GetName().Version + ")";
		}
		
		private void ActOpenExecute(object sender, EventArgs e)
		{
			if (ofdTheme.ShowDialog() == DialogResult.OK)
			{
				_model.LoadTheme(ofdTheme.FileName);
			}
		}

        private void ActSaveExecute(object sender, EventArgs e)
        {
            if (sfdTheme.ShowDialog() == DialogResult.OK)
            {
                _model.SaveTheme(sfdTheme.FileName);
            }
        }

	    private void ActNewExecute(object sender, EventArgs e)
		{
            _model.LoadTheme(DefaultTheme);
		}
		
		private void ActChangeAuthorExecute(object sender, EventArgs e)
		{
		    _model.ChangeAuthor();
		}
		
		private void ActSaveUpdate(object sender, EventArgs e)
		{
		    actSave.Enabled = _model.InUse;
		}
		
		private void ActAboutExecute(object sender, EventArgs e)
		{
			Help.ShowHelp(this, Resources.SiteUrl);
		}
		
		private void ActExitExecute(object sender, EventArgs e)
		{
			Close();
		}

        private void ActMainScreenExecute(object sender, EventArgs e)
        {
            _model.ShowMainScreens();
        }

        private void ActCallScreenExecute(object sender, EventArgs e)
        {
            _model.ShowCallScreen();
        }

        private void ActStandbyScreenExecute(object sender, EventArgs e)
        {
            _model.ShowStandbyScreen();
        }

        private void ActAddIconExecute(object sender, EventArgs e)
        {
            _model.AddIcon();
        }

        private void ActAddIconUpdate(object sender, EventArgs e)
        {
            actAddIcon.Enabled = _model.InUse;
        }

        private void ActRemoveIconExecute(object sender, EventArgs e)
        {
            _model.RemoveIcon();
        }

        private void ActRemoveIconUpdate(object sender, EventArgs e)
        {
            actRemoveIcon.Enabled = _model.InUse;
        }

        private void ActChangeFontExecute(object sender, EventArgs e)
        {
            using (FontDialog dialog = new FontDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    _model.ChangeFont(dialog.Font);
                }
            }
        }

        private void ActChangeFontUpdate(object sender, EventArgs e)
        {
            actChangeFont.Enabled = _model.InUse;
        }

        private void ActChangeAuthorUpdate(object sender, EventArgs e)
        {
            actChangeAuthor.Enabled = _model.InUse;
        }

        private void ActSwitchModeExecute(object sender, EventArgs e)
        {
            _model.SwitchMode();
        }

        private void ActSwitchModeUpdate(object sender, EventArgs e)
        {
            actSwitchMode.Enabled = _model.InUse;
        }
	}
}
